package com.huajiao.management_system.service.impl;

import com.huajiao.management_system.bean.patentRes;
import com.huajiao.management_system.dao.patentResMapper;
import com.huajiao.management_system.service.patentResService;
import com.huajiao.management_system.util.PageQueryUtil2;
import com.huajiao.management_system.util.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class patentResServiceImpl implements patentResService {

    @Resource
    private patentResMapper patentResmapper;
    @Override
    public PageResult selectPage(String Time, String searchtype, String keyword, Integer page) {
        Map param = new HashMap();
        param.put("page", page);
        param.put("limit", 7);
        param.put("Time", Time);
        param.put("searchtype", searchtype);
        param.put("keyword", keyword);
        PageQueryUtil2 pageUtil = new PageQueryUtil2(param);
        if (page == 0 ) {
            PageResult pageResult = new PageResult("错误页数！");
            return pageResult;
        }
        List<patentRes> patentResList = patentResmapper.selectByType(pageUtil);
        int total = patentResmapper.getTotal(pageUtil);
        PageResult pageResult = new PageResult(patentResList,total, pageUtil.getLimit(), pageUtil.getPage());
        return pageResult;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertOne(patentRes patentres) {
        return patentResmapper.insertSelective(patentres);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateOne(patentRes patentres) {
        return patentResmapper.updateByPrimaryKeySelective(patentres);
    }

    @Override
    public Boolean deleteBatch(Integer[] ids) {
        return patentResmapper.deleteBatch(ids) > 0;
    }

    @Override
    public List<patentRes> getAll(String Time, String searchtype, String keyword) {
        Map param = new HashMap();
        param.put("Time", Time);
        param.put("searchtype", searchtype);
        param.put("keyword", keyword);
        return patentResmapper.selectByKeyword(param);
    }
}
